<template>
<el-dialog
    :title="$t('plus.modify')"
    v-model="dialogVisible"
    @close="dialogFormVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="500px"
  >
    <el-form size="small" :model="form" ref="form">
      <el-form-item
        :label="$t('plus.virtual_viewers')"
        :label-width="formLabelWidth"
        prop="name"
        :rules="[{  required: true,  message: $t('plus.input_virtual_people')}]"
      >
        <el-input
          type="number"
          v-model="form.virtualNum"
          :placeholder="$t('plus.input_virtual_people')"
        ></el-input>
      </el-form-item>
      <el-form-item
        :label="$t('plus.is_pinned')"
        prop="audit_status"
        :label-width="formLabelWidth"
      >
        <el-radio v-model="form.isTop" :label="0">{{$t('plus.not_pinned')}}</el-radio>
        <el-radio v-model="form.isTop" :label="1">{{$t('plus.pinned3')}}</el-radio>
      </el-form-item>
      <el-form-item
        :label="$t('plus.is_visible')"
        prop="is_delete"
        :label-width="formLabelWidth"
      >
        <el-radio v-model="form.isDelete" :label="0">{{$t('plus.show')}}</el-radio>
        <el-radio v-model="form.isDelete" :label="1">{{$t('plus.hide')}}</el-radio>
      </el-form-item>
      <el-form-item
        :label="$t('plus.sort')"
        :label-width="formLabelWidth"
        prop="sort"
        :rules="[{  required: true,  message: $t('plus.input_sort_order')}]"
      >
        <el-input
          type="number"
          v-model="form.sort"
          :placeholder="$t('plus.input_sort_order')"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible">{{$t('plus.cancel')}}</el-button>
        <el-button type="primary" @click="confirmFunc" :loading="loading"
          >{{$t('plus.confirm')}}</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<script>
import liveApi from "@/api/live.js";
export default {
  components: {},
  data() {
    var audit_status = (rule, value, callback) => {
      if (value === "" || value === 0) {
        callback(new Error($t("plus.select_status")));
      } else {
        callback();
      }
    };
    return {
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      dialogVisible: false,
      loading: false
    };
  },
  props: ["open", "form"],
  watch: {
    open: function (n, o) {
      if (n != o) {
        this.dialogVisible = n;
      }
    }
  },
  created() {},
  methods: {
    /*审核*/
    confirmFunc() {
      let self = this;
      let params = self.form;
      self.$refs.form.validate(valid => {
        if (valid) {
          self.loading = true;
          liveApi.editRoom(params, true).then(data => {
            self.loading = false;
            ElMessage({
              message: $t("plus.edit_success2"),
              type: "success"
            });
            self.dialogFormVisible(true);
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit("close", true);
      } else {
        this.$emit("close", null);
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.img {
  margin-top: 10px;
}
</style>

